package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.pudao.PuDaoMobileVerification;
import com.ucredit.babel.common.model.third.pudao.PuDaoMobileVerificationData;
import com.ucredit.babel.common.model.third.pudao.PuDaoMobileVerificationRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 朴道-手机号核验
 *
 * @author xj
 */

public class PuDaoMobileVerificationRecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 朴道-手机号核验
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        PuDaoMobileVerificationRecord obj = (PuDaoMobileVerificationRecord) model;
        PuDaoMobileVerificationData data = obj.getData() == null ? new PuDaoMobileVerificationData() : obj.getData();
        PuDaoMobileVerification info = data.getData() == null ? new PuDaoMobileVerification() : data.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        //首次使用距今时长
        sb.append(info.getMoblFstUseProd()).append(CRT001);
        //最后使用是否在180天内
        sb.append(info.getMoblLstUseIsLess180()).append(CRT001);
        //最后使用是否在30天内
        sb.append(info.getMoblLstUseIsLess30()).append(CRT001);
        //最后使用是否在30-90天内
        sb.append(info.getMoblLstUseIs3090()).append(CRT001);
        //最后使用是否在90-180天内
        sb.append(info.getMoblLstUseIs90180()).append(CRT001);
        //是否常用手机号
        sb.append(info.getMoblIsCommon()).append(CRT001);
        //是否默认手机号
        sb.append(info.getMoblIsDefault()).append(CRT001);
        //是否最近使用手机号
        sb.append(info.getMoblIsRecently()).append(CRT001);
        //手机号稳定性评分
        sb.append(info.getMoblStability()).append(CRT001);
        key.set(getKey());
        val.set((sb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_pu_dao_mobile_verification_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.PD_MOBILE_VERIFICATION_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "朴道-手机号核验";
    }
}
